package com.jcl.recruit.depart.logic;

import com.jcl.recruit.org.mapper.JobMapper;
import com.jcl.recruit.org.model.Job;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * @author 刘明新
 * @date 2018/8/7 上午9:18
 */
@Component
public class JobLogic implements JobMapper {

    @Autowired
    private JobMapper jobMapper;

    @Override
    public List<Map<String,Object>> selectAllJobs() {
        List<Map<String,Object>> jobVos = jobMapper.selectAllJobs();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for(Map<String,Object> entity:jobVos){
            entity.put("createtime",sdf.format(entity.get("createtime")));
        }
        return jobVos;
    }

    @Override
    public int insertSelective(Job record) {
        return jobMapper.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(Job record) {
        return jobMapper.updateByPrimaryKeySelective(record);
    }

    public void insertOrUpdate(Job job){
        if(job.getId() == null){
            this.insertSelective(job);
        }else{
            this.updateByPrimaryKeySelective(job);
        }
    }
}
